import java.util.Scanner;

/**
 * 第一题（必答）
 * 由于历史原因，导致项目在数据库之中时间字段记录存在 2 个时区：中国上海 CST（东八区）以及标准时间 UTC，现
 * 在从数据之中获取随机数量的时间字段列表（24 小时制，格式为：小时:分钟 "HH:MM"+时区），请找出列表中任意两个时
 * 间的最小时间差并以分钟数表示。
 * 备注：只是当前发现了 2 个时区，数据库之中仍可能存在其他时区，但均为标准时区标记；
 * 示例 1：输入：timePoints = ["08:01CST","00:00UTC"]，输出：1
 * 示例 2：输入：timePoints = ["00:03CST","08:00CST","00:00UTC"]，输出：0
 * 示例 3：输入：timePoints = ["00:03CST","18:00CST","00:10UTC"]，输出：487
 */


public class Main {
    public static void main(String[] args) {
        System.out.println("请输入时间字段列表:");
        //输入timePoints  如：timePoints = ["00:03CST","08:00CST","00:00UTC"];
        Scanner sc = new Scanner(System.in);
        String timePoints = sc.next();
        //删除前后的方括号
        timePoints = timePoints.replace("[", "");
        timePoints = timePoints.replace("]", "");
        String[] timeStrArray = timePoints.split(",");
        //将各时区段的时间转化成分钟，世界时UTC自动加8小时
        int[] timePointsLength = getMinutes(timeStrArray);
        //比较timePointsLength内相差最小的值即可
        int res = Integer.MAX_VALUE;
        for (int i = 0; i < timePointsLength.length; i++) {
            for (int j = i+1; j < timePointsLength.length; j++) {
                int val = Math.abs(timePointsLength[j] - timePointsLength[i]);
                res = res>val?val:res;
            }
        }
        System.out.println("最小时间差: "+res);
    }


    private static int[] getMinutes(String[] timeStrArray) {
        int[] timePointsLength = new int[timeStrArray.length];
        for (int i = 0; i < timeStrArray.length; i++) {
            int hour = 0;
            if (timeStrArray[i].contains("UTC")) {
                //转化成对应的小时,UTC就加8
                hour = Integer.valueOf(timeStrArray[i].substring(1, 3)) + 8;
            } else if (timeStrArray[i].contains("CST")) {
                hour = Integer.valueOf(timeStrArray[i].substring(1, 3));
            } else {
                System.out.println("检测到其它时区，请排查");
            }
            //转化成对应的分钟
            int minute = Integer.valueOf(timeStrArray[i].substring(4, 6));
            timePointsLength[i] = hour*60+minute;
        }
        return timePointsLength;
    }
}